Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first version of the Rebalancer with flashloan #109

Closed
wants to merge 61 commits into from

Conversation

sogipec
Copy link
Contributor

@sogipec sogipec commented Mar 21, 2024

No description provided.

@sogipec sogipec force-pushed the flashloan-rebalancer branch from dbb9fff to e1b7925 Compare March 22, 2024 14:20
@sogipec sogipec changed the base branch from main to feat--oracles-with-firewalls-on-mint-and-burn March 22, 2024 14:21
@sogipec sogipec force-pushed the flashloan-rebalancer branch from a463e1a to 990aaba Compare March 25, 2024 07:37
Copy link

codecov bot commented Mar 25, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 21 lines in your changes are missing coverage. Please review.

Project coverage is 97.75%. Comparing base (ec7d7ab) to head (4086d5d).

Files Patch % Lines
contracts/helpers/RebalancerFlashloan.sol 12.50% 21 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #109      +/-   ##
===========================================
- Coverage   100.00%   97.75%   -2.25%     
===========================================
  Files           22       23       +1     
  Lines          912      936      +24     
===========================================
+ Hits           912      915       +3     
- Misses           0       21      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

contracts/helpers/RebalancerFlashloan.sol Fixed Show fixed Hide fixed
contracts/helpers/RebalancerFlashloan.sol Fixed Show fixed Hide fixed
contracts/helpers/RebalancerFlashloan.sol Fixed Show fixed Hide fixed
Comment on lines 53 to 94
function onFlashLoan(
address initiator,
address,
uint256 amount,
uint256 fee,
bytes calldata data
) external returns (bytes32) {
if (msg.sender != address(FLASHLOAN) || initiator != address(this) || fee != 0) revert NotTrusted();
uint256 typeAction = abi.decode(data, (uint256));
address tokenOut;
address tokenIn;
if (typeAction == 1) {
// Increase yield exposure action: we bring in the vault
tokenOut = address(COLLATERAL);
tokenIn = address(VAULT);
} else {
// Decrease yield exposure action: we bring in the collateral
tokenIn = address(COLLATERAL);
tokenOut = address(VAULT);
}
uint256 amountOut = TRANSMUTER.swapExactInput(amount, 0, AGTOKEN, tokenOut, address(this), block.timestamp);
if (typeAction == 1) amountOut = VAULT.deposit(amountOut, address(this));
else amountOut = VAULT.redeem(amountOut, address(this), address(this));
uint256 allowance = IERC20(tokenIn).allowance(address(this), address(TRANSMUTER));
if (allowance < amountOut)
IERC20(tokenIn).safeIncreaseAllowance(address(TRANSMUTER), type(uint256).max - allowance);
uint256 amountStableOut = TRANSMUTER.swapExactInput(
amountOut,
0,
tokenIn,
AGTOKEN,
address(this),
block.timestamp
);

if (amount > amountStableOut) {
uint256 subsidy = amount - amountStableOut;
orders[tokenIn][tokenOut].subsidyBudget -= subsidy.toUint112();
budget -= subsidy;
emit SubsidyPaid(tokenIn, tokenOut, subsidy);
}

return CALLBACK_SUCCESS;
}

Check notice

Code scanning / Slither

Block timestamp Low

@sogipec sogipec force-pushed the flashloan-rebalancer branch 2 times, most recently from e9ce80c to 6127b54 Compare March 28, 2024 11:37
Copy link
Contributor

@GuillaumeNervoXS GuillaumeNervoXS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we may do any tokenIn or tokenOut with this contract that come along the way

Not really in this implementation in can only be VAULT or COLLATERAL

contracts/helpers/RebalancerFlashloan.sol Show resolved Hide resolved
contracts/helpers/RebalancerFlashloan.sol Show resolved Hide resolved
contracts/helpers/RebalancerFlashloan.sol Show resolved Hide resolved
contracts/helpers/RebalancerFlashloan.sol Outdated Show resolved Hide resolved
@sogipec sogipec force-pushed the flashloan-rebalancer branch from 6094b11 to ff8d4e1 Compare March 28, 2024 15:22
Comment on lines +36 to +49
function adjustYieldExposure(
uint256 amountStablecoins,
uint8 increase,
address collateral,
address vault
) external {
if (!TRANSMUTER.isTrustedSeller(msg.sender)) revert NotTrusted();
FLASHLOAN.flashLoan(
IERC3156FlashBorrower(address(this)),
address(AGTOKEN),
amountStablecoins,
abi.encode(increase, collateral, vault)
);
}
Base automatically changed from feat--oracles-with-firewalls-on-mint-and-burn to main April 2, 2024 08:54
@sogipec sogipec force-pushed the flashloan-rebalancer branch from ff8d4e1 to 0267e88 Compare April 5, 2024 17:57
address(this),
block.timestamp
);
if (amount > amountStableOut) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have a min amount out check

@sogipec sogipec closed this Apr 8, 2024
@sogipec sogipec deleted the flashloan-rebalancer branch April 8, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants